package il.technion.cs236369.webserver.simpleServlets;


/**
 * a class representing a geographic coordinates.
 * 
 * @author itamar talmi and ofir haviv
 */
public class GeoCoordinate {
	public GeoCoordinate(String geoCoordStr) throws Exception {
		String[] splitted = geoCoordStr.split("&");
		if (splitted.length != 2)
			throw new Exception(
					"coordinate is not in correct format. example for correct format: 33.456&31.978.");
		this.latitude = (Float.parseFloat(splitted[0]));
		this.longitude = (Float.parseFloat(splitted[1]));
	}

	public float getLatitude() {
		return latitude;
	}

	public float getLongitude() {
		return longitude;
	}

	private float latitude;
	private float longitude;

	/**
	 * calculates Euclidian distance between to geographic coordinates.
	 * 
	 * @param c1
	 *            - first geographic coordinate
	 * @param c2
	 *            - second geographic coordinate
	 * @return Euclidian distance
	 */
	public static double EuclidianDistance(GeoCoordinate c1,
			GeoCoordinate c2) {
		double squaredDistance = c1.latitude * c2.latitude + c1.longitude
				* c2.longitude;
		return Math.sqrt(squaredDistance);
	}
}
